package cn.edu.gcu.giftems.pojos;

import java.util.HashSet;
import java.util.Set;

/**
 * 礼品类
 *
 * @author ZhengHQ
 * @create 2018-09-24
 * @see
 */
public class Gift {
    /** id **/
    private int id;
    /** 名称 **/
    private String name;
    /**图片**/
    private String pic;
    /**款式价格**/
    private double price;
    /** 库存 **/
    private int number;
    private int status;
    private Type type;
    private Set<OrderItem> orderItems = new HashSet<OrderItem>();
    private String typeName;
    private int typeId;

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public int getTypeId() {
        return typeId;
    }

    public void setTypeId(int typeId) {
        this.typeId = typeId;
    }

    public Gift() {
    }

    public Gift(String name, String pic, double price, int number, int status, Type type) {
        this.name = name;
        this.pic = pic;
        this.price = price;
        this.number = number;
        this.type = type;
        this.status = status;
    }

    public Gift(int id, String name, String pic, double price, int number, int status, int typeId, String typeName) {
        this.id = id;
        this.name = name;
        this.pic = pic;
        this.price = price;
        this.number = number;
        this.typeName = typeName;
        this.status = status;
        this.typeId = typeId;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPic() {
        return pic;
    }

    public void setPic(String pic) {
        this.pic = pic;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public Status getStatus() {
        return Status.fromCode(status);
    }

    public int getIntStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status.getCode();
    }

    public Set<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(Set<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    @Override
    public String toString() {
        return "Gift{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", pic='" + pic + '\'' +
                ", price=" + price +
                ", number=" + number +
                ", type=" + type.toString() +
                //", typename=" + type.getName() +
                '}';
    }

    public enum Status {
        DAIFABU(0), YIFABU(1);

        int code;

        Status(int code) {
            this.code = code;
        }

        public static Status fromCode(int code) {
            switch (code) {
                case 0:
                    return DAIFABU;
                case 1:
                    return YIFABU;
                default:
                    throw new IllegalArgumentException();
            }
        }

        @Override
        public String toString() {
            switch (code) {
                case 0:
                    return "待发布";
                case 1:
                    return "已发布";
            }
            return null;
        }

        public int getCode() {
            return code;
        }
    }
}
